from typing import Optional
from pydantic import BaseModel
from datetime import date, datetime
from enum import Enum


class CourseBase(BaseModel):
    course_name: str
    course_code: str
    teacher_id: Optional[int] = None
    credit: Optional[float] = None
    department: Optional[str] = None
    description: Optional[str] = None
    max_num: Optional[int] = None
    num: int = 0
    status: Optional[int] = None
    semester_id: Optional[int] = None


class CourseCreate(CourseBase):
    pass


class CourseUpdate(BaseModel):
    course_name: Optional[str] = None
    course_code: Optional[str] = None
    teacher_id: Optional[int] = None
    credit: Optional[float] = None
    department: Optional[str] = None
    description: Optional[str] = None
    max_num: Optional[int] = None
    num: Optional[int] = None
    status: Optional[int] = None
    semester_id: Optional[int] = None


class Course(CourseBase):
    course_id: int
    create_time: datetime
    update_time: Optional[datetime] = None

    class Config:
        orm_mode = True


class SemesterBase(BaseModel):
    name: str
    start_time: date
    week_num: int


class SemesterCreate(SemesterBase):
    pass


class SemesterUpdate(BaseModel):
    name: Optional[str] = None
    start_time: Optional[date] = None
    week_num: Optional[int] = None


class Semester(SemesterBase):
    id: int
    create_time: Optional[datetime] = None

    class Config:
        orm_mode = True


class GenderEnum(str, Enum):
    male = "male"
    female = "female"


class TeacherBase(BaseModel):
    name: str
    gender: GenderEnum
    birthday: Optional[date] = None
    department: Optional[str] = None
    title: Optional[str] = None
    phone: Optional[str] = None
    address: Optional[str] = None
    id_card: Optional[str] = None


class TeacherCreate(TeacherBase):
    pass


class TeacherUpdate(BaseModel):
    name: Optional[str] = None
    gender: Optional[GenderEnum] = None
    birthday: Optional[date] = None
    department: Optional[str] = None
    title: Optional[str] = None
    phone: Optional[str] = None
    address: Optional[str] = None
    id_card: Optional[str] = None


class Teacher(TeacherBase):
    teacher_id: int
    create_time: Optional[datetime] = None

    class Config:
        orm_mode = True
